package cj.web.marry.controllers;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import cj.utils.Constants;
import cj.utils.Page;
import cj.web.marry.constants.GameTypeEnum;
import cj.web.marry.dao.GameDAO;

@Path("game")
public class GameController{
	
	protected static final Log logger = LogFactory.getLog(GameController.class); 
	
	@Autowired
	private GameDAO gameDao;
	
	@Get("home")  //活动页面
	public String home(Model model, HttpServletRequest request) throws Exception{
		model.add("GameTypeEnum", EnumSet.allOf(GameTypeEnum.class));
		return "/views/marry/activity/historyEvents.vm";
	}
	
	@Get("getList")  //活动页面
	public String home(@Param("type") int type,@Param("start") int start,@Param("length") int length,
			Model model, HttpServletRequest request) throws Exception{
		
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		List<Map> gamels = gameDao.query(start*length,length,type);
		
		
		int totalCount = gameDao.querySize(type);
		//分页计算
		Page p= new Page<Map>(0, length, gamels, totalCount);
		jo.put("list", gamels);
		jo.put("repsize", p.getTotalPages());
		jo.put("totalCount", totalCount);
		
		return "@"+jo.toString();
	}
}